/**
 * Copyright (c) 2020 kedacom
 * OpenATC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 **/
<template>
  <div>
    <div v-if="!gisHomeVisible">
      <SimpleHome v-show="this.homesimple === 'true'"/>
      <DefaultHome v-show="this.homesimple === 'false' || !this.homesimple" />
    </div>
    <div v-if="gisHomeVisible">
      <GisHome />
    </div>
  </div>
</template>
<script>
import SimpleHome from './simplehome.vue'
import DefaultHome from './defaulthome.vue'
import GisHome from './gishome.vue'
import { SystemconfigApi } from '../../api/systemconfig.js'
import { getMenuVisible } from '../../utils/auth'

export default {
  data () {
    return {
      homesimple: '',
      gisHomeVisible: false
    }
  },
  components: {
    SimpleHome,
    DefaultHome,
    GisHome
  },
  created () {
    this.isShowGis()
    this.gethomesimple()
  },
  methods: {
    gethomesimple () {
      return new Promise((resolve, reject) => {
        let reqData = {
          module: 'home',
          isValid: true
        }
        SystemconfigApi.GetSystemconfigList(reqData).then((data) => {
          let res = data.data
          if (!res.success) {
            console.log('datas:' + res)
            throw new Error('get JupyterUrl error')
          } else {
            for (let config of data.data.data) {
              if (config['key'] === 'homesimple') {
                this.homesimple = config['value']
              }
            }
            resolve(data.data.data)
          }
        })
      })
    },
    isShowGis () {
      this.gisHomeVisible = false
      console.log('getMenuVisible', getMenuVisible('gis'))
      if (getMenuVisible('gis') === 'true') {
        this.gisHomeVisible = true
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
